<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $lang['PAGE_TITLE_EDIT_PROJECT']; ?></title>
<?php include("header.php"); ?>
	<center>
	<table cellpadding="0" cellspacing="0" width="93%">
	<tr>
		<td align="left">
			<br /><br />
			<?php 
			if(!$session->logged_in)
			{
				echo "<center><h3>You must be logged in to edit your project.</h3></center>";
			}
			else if(isset($_GET['edit']))
			{
				$project = $database->getProject($_GET['edit']);
				if($project=="")
				{
					echo "<center>No Project Found</center>";
				}
				else
				{
					$resul = $database->query("SELECT * FROM ".TBL_PROJECT_MEMBERS." WHERE projectID='".$project['id']."' AND username='".$session->username."'");
					$projectMember = mysql_fetch_array($resul);
					
					if($project['creator']==$session->username || $session->userlevel>=MANAGER_LEVEL || $projectMember['userlevel']>=PROJECT_MANAGER)
					{
						if(isset($_SESSION['editProjectFieldSuccess']))
						{
							if($_SESSION['editProjectFieldSuccess'])
							{
								echo "<center><table cellpadding=\"10\" cellspacing=\"0\" class=\"border\" width=\"50%\">";
								echo "<tr><td>";
								echo "<center><h3>Edit Project Successful!</h3></center>";
								echo "<center><a href=\"viewProject.php?id=".$project['id']."\">View Project</a></center>";
								echo "</td></tr>";
								echo "</table></center>";
								echo "<br /><br />";
							}
							else
							{
								echo "<center><table cellpadding=\"10\" cellspacing=\"0\" class=\"border\" width=\"50%\">";
								echo "<tr><td>";
								echo "<center><h3>Edit Project Failed!</h3></center>";
								echo "<center>".$form->error("content")."</center><br />";
								echo "<center>".$form->value("content")."</center>";
								echo "</td></tr>";
								echo "</table></center>";
								echo "<br /><br />";
							}
							unset($_SESSION['editProjectFieldSuccess']);
						}
			?>
			<table cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td valign="top">
					<center>
					<table cellpadding="10" cellspacing="0" class="border" width="100%">
					<tr><td class="title" align="left"><?php echo $lang['PROFILE_PROJECT_MENU']; ?></td></tr>
					<tr>
						<td>
							<center>
							<table cellpadding="1" cellspacing="0">
							<tr>
								<td><a href="viewProject.php?id=<?php echo $_GET['edit']; ?>"><?php echo $lang['EDIT_PROJECT_BACKTOPROJECT']; ?></a></td>
							</tr>
							<tr>
								<td><a href="editProjectResources.php?id=<?php echo $_GET['edit']; ?>"><?php echo $lang['EDIT_PROJECT_RESOURCES_NEED']; ?></a></td>
							</tr>
							<tr>
								<td><a href="editProjectNews.php?id=<?php echo $_GET['edit']; ?>"><?php echo $lang['EDIT_PROJECT_EDIT_NEWS']; ?></a></td>
							</tr>
							<?php
							if($projectMember['userlevel']>=PROJECT_OWNER)
							{
							?>
							<tr>
								<td><a href="editProjectMembers.php?id=<?php echo $_GET['edit']; ?>"><?php echo $lang['EDIT_PROJECT_EDIT_MEMBERS']; ?></a></td>
							</tr>
							<?php } ?>
							</table>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
					<center>
					<form action="includes/process.php" method="post" enctype="multipart/form-data">
					<input type="hidden" name="subUploadProjectPic" value="<?php echo $_GET['edit']; ?>" />
					<table cellpadding="10" cellspacing="0" class="border" width="100%">
					<tr><td class="title" align="left">Logo:</td></tr>
					<tr>
						<td>
							<center><?php echo $form->error('uploading'); ?></center>
							<center><img width="200" <?php if($project['logoPic']==''){ echo "src=\"".DEFAULT_PROJECT_PIC."\""; }else{ echo "src=\"".$project['logoPic']."\""; }?> /></center>
							<center><font size="-2" color="#666666">Max 200 x 200, JPEG, GIF, 50KB</font></center>
							<br />
							<center><input type="file" name="file" id="file" /></center>
							<?php echo $form->error('upload'); ?>
						</td>
					</tr>
					<tr>
						<td align="right"><input type="submit" name="submit" value="Upload" /></td>
					</tr>
					</table>
					</form>
					</center>
					<br />
					<center>
					<table cellpadding="10" cellspacing="0" class="border" width="100%">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_INFO']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td align="left">Web Site: <? echo $form->error("link"); ?></td>
							</tr>
							<tr>
								<td align="left"><input type="text" name="link" size="45" maxlength="256" style="background-color: #bcc6e1;" value="<? echo $project['link']; ?>" /></td>
							</tr>
							<tr>
								<td align="center"><font color="#666666" size="-2"><i>(Example: http://www.futuragora.pt/)</i></font></td>
							</tr>
							<tr>
								<td align="left"><?php echo $lang['EDIT_PROJECT_DONATION_NEEDED']; ?> <? echo $form->error("moneyNeeded"); ?></td>
							</tr>
								<td align="left"><input type="text" name="moneyNeeded" size="45" maxlength="10" style="background-color: #bcc6e1;" value="<? echo $project['moneyNeeded']; ?>" /></td>
							</tr>
							<tr>
								<td align="left">E-mail: <? echo $form->error("email"); ?></td>
							</tr>
							<tr>
								<td align="left"><input type="text" name="email" size="45" maxlength="50" style="background-color: #bcc6e1;" value="<? echo $project['email']; ?>" /></td>
							</tr>
							<tr>
								<td align="right">
									<input type="hidden" name="subEditProjectDetails" value="<?php echo $_GET['edit']; ?>">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
					<center>
					<table cellpadding="10" cellspacing="0" class="border" width="100%">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_PREFERENCES']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td colspan="2"><center><b><?php echo $lang['EDIT_PROJECT_MEMBERSHIP']; ?></b></center></td><td></td>
							</tr>
							<tr>
								<td align="right"><input type="radio" <?php if($project['isPrivate']=='0'){ echo "checked=\"checked\""; } ?> name="isPrivate" value="0"></td>
								<td align="left">Public</td>
							</tr>
							<tr>
								<td align="right"><input type="radio" <?php if($project['isPrivate']=='1'){ echo "checked=\"checked\""; } ?> name="isPrivate" value="1"></td>
								<td align="left">Private</td>
							</tr>
							<tr>
								<td colspan="2"><br /><center><b><?php echo $lang['EDIT_PROJECT_APLICATION_DISPLAY']; ?></b></center></td><td></td>
							</tr>
							<tr>
								<td align="right"><input type="checkbox" <?php if($project['allowApply']=='1'){ echo "checked=\"checked\""; } ?> name="allowApply" value="1"></td>
								<td align="left">Allow users to apply, and show the application.</td>
							</tr>
							<tr>
								<td colspan="2"><br /><center><b><?php echo $lang['EDIT_PROJECT_APLICATION_NOTIFY']; ?></b></center></td><td></td>
							</tr>
							<tr>
								<td align="right"><input type="radio" <?php if($project['applyNotify']=='0'){ echo "checked=\"checked\""; } ?> name="applyNotify" value="0"></td>
								<td align="left">Notify me through e-mail of an applicant.</td>
							</tr>
							<tr>
								<td align="right"><input type="radio" <?php if($project['applyNotify']=='1'){ echo "checked=\"checked\""; } ?> name="applyNotify" value="1"></td>
								<td align="left">Notify me through messages of an applicant.</td>
							</tr>
							<tr>
								<td colspan="2" align="right">
									<input type="hidden" name="subEditProjectPreferences" value="<?php echo $_GET['edit']; ?>">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
				</td>
				<td width="10px"></td>
				<td valign="top">
					<center>
					<table cellpadding="10" cellspacing="0" class="border">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_NAME']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<input type="hidden" name="projectID" value="<?php echo $_GET['edit']; ?>" />
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td><input type="text" name="content" size="65" maxlength="50" value="<?php echo $project['name']; ?>" /></td>
								<td align="right">
									<input type="hidden" name="subEditProjectField" value="name">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
					<center>
					<table cellpadding="10" cellspacing="0" class="border">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_DESC']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<input type="hidden" name="projectID" value="<?php echo $_GET['edit']; ?>" />
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td><textarea name="content" rows="5" cols="60" style="background-color: #bcc6e1;"><? echo $project['description']; ?></textarea></td>
							</tr>
							<tr>
								<td align="right">
									<font size="-2" color="#666666"><i>(Can use &lt;a&gt;, &lt;font&gt;, &lt;b&gt;, &lt;i&gt;)</i></font>
									<input type="hidden" name="subEditProjectField" value="description">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
					<center>
					<table cellpadding="10" cellspacing="0" class="border">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_DETAILS']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<input type="hidden" name="projectID" value="<?php echo $_GET['edit']; ?>" />
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td><textarea name="content" rows="10" cols="60" style="background-color: #bcc6e1;"><? echo $project['details']; ?></textarea></td>
							</tr>
							<tr>
								<td align="right">
									<font size="-2" color="#666666"><i>(Can use &lt;a&gt;, &lt;font&gt;, &lt;b&gt;, &lt;i&gt;)</i></font>
									<input type="hidden" name="subEditProjectField" value="details">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
					<center>
					<table cellpadding="10" cellspacing="0" class="border">
					<tr><td class="title" align="left"><?php echo $lang['EDIT_PROJECT_SPECS']; ?></td></tr>
					<tr>
						<td>
							<center>
							<form action="includes/process.php" method="POST">
							<input type="hidden" name="projectID" value="<?php echo $_GET['edit']; ?>" />
							<table border="0" cellspacing="0" cellpadding="3">
							<tr>
								<td><textarea name="content" rows="20" cols="60" style="background-color: #bcc6e1;"><? echo $project['application']; ?></textarea></td>
							</tr>
							<tr>
								<td align="right">
									<input type="hidden" name="subEditProjectField" value="application">
									<input type="submit" value="Save">
								</td>
							</tr>
							</table>
							</form>
							</center>
						</td>
					</tr>
					</table>
					</center>
					<br />
				</td>
			</tr>
			</table>
			<?php
					}
				}
			}
			?>
		</td>
	</tr>
	</table>
	</center>
<?php include("footer.php"); ?>